import random
import string
import time

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.user_security_settings_locator import UserSecuritySettingsLocator
from Case.python_ui.PageLocate.user_contacts_list_locator import UserContactsListLocator
from Case.python_ui.Common.business_common_tool import BusinessCommonTools
from Case.python_ui.Test_data.login_data import Logindata


class UserContactsListPages(Basepage):

    # 进入contacts list页面
    def click_contact_list(self):
        time.sleep(2)
        doc = "进入contacts list页面"
        self.wait_elevisble(UserSecuritySettingsLocator.contacts_list_setting, doc)
        self.click_element(UserSecuritySettingsLocator.contacts_list_setting, doc)
        self.wait_elevisble(UserContactsListLocator.contacts_list_title, doc)
        assert self.get_element(UserContactsListLocator.contacts_list_title, doc).text == "Contacts List"

    # 由contacts list返回security setting页
    def back_to_security_setting(self):
        time.sleep(2)
        doc = "返回contacts list上一页"
        self.wait_elevisble(UserContactsListLocator.contacts_list_back, doc)
        self.click_element(UserContactsListLocator.contacts_list_back, doc)
        self.wait_elevisble(UserSecuritySettingsLocator.security_settings_title, doc)
        assert self.get_element(UserSecuritySettingsLocator.security_settings_title, doc).text == "Security Setting"

    # 新增contact
    def add_contact(self, cmdopt, get_database_source):
        email = Logindata.user_data[cmdopt]['user2']['username']
        self.click_contact_list()
        time.sleep(2)
        doc = "成功新增contact"
        self.click_element(UserContactsListLocator.add_contact_button, doc)
        time.sleep(1)
        self.send_keys(UserContactsListLocator.add_contact_layer_name_input, 'user2', doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, email, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)
        time.sleep(1)
        contact_verify_code = BusinessCommonTools().get_verification_code(cmdopt, email, get_database_source)
        time.sleep(2)
        self.click_element(UserContactsListLocator.add_contact_layer_switch, doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_code_input, contact_verify_code, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.col_email_value, doc).text == email

    # 邮箱格式输入错误
    def verify_email_form_wrong(self):
        self.click_contact_list()
        time.sleep(2)
        doc = "邮箱格式错误提示"
        self.wait_elevisble(UserContactsListLocator.add_contact_button, doc)
        self.click_element(UserContactsListLocator.add_contact_button, doc)
        time.sleep(1)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, 'wrong', doc)
        time.sleep(1)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_email_form_alert, doc)
        assert self.get_element(UserContactsListLocator.add_contact_layer_email_form_alert,
                                doc).text == "Please input the correct email address."

    # 验证码错误
    def verify_code_wrong(self, cmdopt):
        email = Logindata.user_data[cmdopt]['user3']['username']
        self.click_contact_list()
        time.sleep(1)
        doc = "验证码错误提示"
        self.wait_elevisble(UserContactsListLocator.add_contact_button, doc)
        self.click_element(UserContactsListLocator.add_contact_button, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_name_input, doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_name_input, 'user3', doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, email, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code_loading, doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_code_input, 'wrong', doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        time.sleep(1)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_pup_alert, doc)
        assert self.get_element(UserContactsListLocator.add_contact_layer_pup_alert, doc).text.startswith(
            'Incorrect verification code.')

    # 不输入验证码
    def verify_code_empty(self, cmdopt):
        email = Logindata.user_data[cmdopt]['user4']['username']
        self.click_contact_list()
        time.sleep(2)
        doc = "邮箱格式错误提示"
        self.wait_elevisble(UserContactsListLocator.add_contact_button, doc)
        self.click_element(UserContactsListLocator.add_contact_button, doc)
        time.sleep(1)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_name_input, doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_name_input, 'user4', doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, email, doc)

        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code_loading, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        time.sleep(1)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_code_empty_alert, doc)
        assert self.get_element(UserContactsListLocator.add_contact_layer_code_empty_alert,
                                doc).text == "Please enter email verification code."

    # 邮箱输入主用户
    def email_input_self(self, cmdopt):
        email = Logindata.user_data[cmdopt]['user']['username']
        self.click_contact_list()
        time.sleep(1)
        doc = "邮箱格式错误提示"
        self.click_element(UserContactsListLocator.add_contact_button, doc)
        time.sleep(1)
        self.send_keys(UserContactsListLocator.add_contact_layer_name_input, 'user', doc)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, 'Etest1@sigma.com', doc)
        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)
        time.sleep(2)
        self.send_keys(UserContactsListLocator.add_contact_layer_code_input, 'easy', doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.add_contact_layer_pup_alert,
                                doc).text == "This email is the default email for receiving invoices. Please enter a different email address"

    def delete_contact(self):
        time.sleep(5)
        doc = "删除contact"
        self.wait_elevisble(UserContactsListLocator.contacts_list_delete, doc)
        self.click_element(UserContactsListLocator.contacts_list_delete, doc)
        self.wait_elevisble(UserContactsListLocator.delete_contact_confirm_button, doc)
        self.click_element(UserContactsListLocator.delete_contact_confirm_button, doc)
        assert self.get_element(UserContactsListLocator.contact_list_delete_success, doc)

    def select_contact(self, cmdopt):
        full_keyword = Logindata.user_data[cmdopt]['user2']['username']
        part_keyword = full_keyword[4:8]
        wrong_keyword = Logindata.user_data[cmdopt]['user3']['username']

        time.sleep(5)

        doc = "精确查询contacts list"
        self.send_keys(UserContactsListLocator.select_keyword_input, full_keyword, doc)
        self.click_element(UserContactsListLocator.select_icon, doc)
        self.wait_eleinvisble(UserContactsListLocator.contacts_list_loading, doc)
        assert self.get_element(UserContactsListLocator.col_email_value, doc).text == full_keyword
        self.refresh_page()
        doc = "模糊查询contacts List"
        self.wait_elevisble(UserContactsListLocator.select_keyword_input, doc)
        self.send_keys(UserContactsListLocator.select_keyword_input, part_keyword, doc)
        self.click_element(UserContactsListLocator.select_icon, doc)
        self.wait_eleinvisble(UserContactsListLocator.contacts_list_loading, doc)
        assert part_keyword in self.get_element(UserContactsListLocator.col_email_value, doc).text
        self.refresh_page()
        doc = "未查询到对应contact"
        self.wait_elevisble(UserContactsListLocator.select_keyword_input, doc)
        self.send_keys(UserContactsListLocator.select_keyword_input, wrong_keyword, doc)
        self.click_element(UserContactsListLocator.select_icon, doc)
        self.wait_eleinvisble(UserContactsListLocator.contacts_list_loading, doc)
        assert self.get_element(UserContactsListLocator.contacts_list_empty, doc)
        self.refresh_page()

    # 分别编辑name,invoice,email
    def edit_contact(self, cmdopt, get_database_source):
        new_name = "user6"
        time.sleep(3)
        doc = "编辑name并保存"
        self.wait_elevisble(UserContactsListLocator.contacts_list_edit, doc)
        self.click_element(UserContactsListLocator.contacts_list_edit, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_name_input, doc)
        self.get_element(UserContactsListLocator.add_contact_layer_name_input, doc).send_keys(Keys.CONTROL, "a")
        self.get_element(UserContactsListLocator.add_contact_layer_name_input, doc).send_keys(Keys.BACKSPACE)
        self.send_keys(UserContactsListLocator.add_contact_layer_name_input, new_name, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        assert self.get_element(UserContactsListLocator.edit_success_tip, doc)
        self.refresh_page()
        doc = "编辑invoice并保存"
        self.wait_elevisble(UserContactsListLocator.contacts_list_edit, doc)
        self.click_element(UserContactsListLocator.contacts_list_edit, doc)

        self.wait_elevisble(UserContactsListLocator.edit_contact_layer_switch, doc)
        self.click_element(UserContactsListLocator.edit_contact_layer_switch, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        assert self.get_element(UserContactsListLocator.edit_success_tip, doc)
        self.refresh_page()

        doc = "编辑email并保存"
        self.wait_elevisble(UserContactsListLocator.contacts_list_edit, doc)
        self.click_element(UserContactsListLocator.contacts_list_edit, doc)

        new_email = Logindata.user_data[cmdopt]['user6']['username']
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_email_input, doc)
        self.get_element(UserContactsListLocator.add_contact_layer_email_input, doc).send_keys(Keys.CONTROL, "a")
        self.get_element(UserContactsListLocator.add_contact_layer_email_input, doc).send_keys(Keys.BACKSPACE)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, new_email, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code_loading, doc)
        contact_verify_code = BusinessCommonTools().get_verification_code(cmdopt, new_email, get_database_source)
        self.get_element(UserContactsListLocator.add_contact_layer_code_input, doc).send_keys(Keys.CONTROL, "a")
        self.get_element(UserContactsListLocator.add_contact_layer_code_input, doc).send_keys(Keys.BACKSPACE)
        self.send_keys(UserContactsListLocator.add_contact_layer_code_input, contact_verify_code, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)
        assert self.get_element(UserContactsListLocator.edit_success_tip, doc)
        self.refresh_page()

        doc = "编辑email输入错误验证码"
        self.wait_elevisble(UserContactsListLocator.contacts_list_edit, doc)
        self.click_element(UserContactsListLocator.contacts_list_edit, doc)

        new_email2 = Logindata.user_data[cmdopt]['admin']['username']
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_email_input, doc)
        self.get_element(UserContactsListLocator.add_contact_layer_email_input, doc).send_keys(Keys.CONTROL, "a")
        self.get_element(UserContactsListLocator.add_contact_layer_email_input, doc).send_keys(Keys.BACKSPACE)
        self.send_keys(UserContactsListLocator.add_contact_layer_email_input, new_email2, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code, doc)
        self.click_element(UserContactsListLocator.add_contact_layer_send_code, doc)
        self.wait_elevisble(UserContactsListLocator.add_contact_layer_send_code_loading, doc)
        self.get_element(UserContactsListLocator.add_contact_layer_code_input, doc).send_keys(Keys.CONTROL, "a")
        self.get_element(UserContactsListLocator.add_contact_layer_code_input, doc).send_keys(Keys.BACKSPACE)
        self.send_keys(UserContactsListLocator.add_contact_layer_code_input, "wrong", doc)
        self.click_element(UserContactsListLocator.add_contact_layer_confirm_button, doc)

        self.wait_elevisble(UserContactsListLocator.add_contact_layer_pup_alert, doc)
        print(self.get_element(UserContactsListLocator.add_contact_layer_pup_alert, doc).text)
        assert self.get_element(UserContactsListLocator.add_contact_layer_pup_alert, doc).text.startswith(
            'Incorrect verification code.')
        self.refresh_page()

    # ========================================Product Redis Pages==============================================
    route = {
        "redis purchase": "/product/redis/purchase"
    }

    options = {
        "edition": ["Community", "Enterprise"],
        "version": ["Redis 5.0", "Redis 4.0"],
        "architecture type": ["Cluster", "Standard", "Read/Write Splitting"],
        "node type": ["1 Read Replica", "3 Read Replicas", "5 Read Replicas"],
        "validity period": ["1 Month", "2 Months", "3 Months", "6 Months", "1 Year", "2 Years", "3 Years"]
    }

    table_columns = {
        "Redis console": ["Instance ID/Name", "Status", "Edition", "Version", "Instance Type", "Zone", "Network Type", "Organization", "Actions"]
    }

    def enter_product_by_name(self, product_name, open_new_window=False):
        """
        param open_new_window: switch to new window if product page need
        """
        doc = f"进入{product_name}产品页面"
        self.click_element(UserContactsListLocator.product_drawer, doc)
        product_item_xpath = f"(//div[contains(@class,'columnItemSub') and text()='{product_name}'])[1]"
        time.sleep(10)
        self.wait_elevisble((By.XPATH, product_item_xpath), doc)
        self.click_element((By.XPATH, product_item_xpath), doc)
        time.sleep(5)
        if open_new_window:
            self.switch_to_new_window()

    def switch_to_newest_window(self):
        """ 进入最新打开的页面 """
        window_handles = self.driver.window_handles
        self.driver.switch_to.window(window_handles[-1])

    def enter_redis_purchase(self):
        doc = "进入Redis购买页面"
        self.enter_product_by_name("Redis", True)
        self.click_element(UserContactsListLocator.redis_create_instance, doc)
        time.sleep(1)
        self.switch_to_newest_window()
        assert self.route["redis purchase"] in self.driver.current_url

        # 测试账号在点击第二个region的情况下，部分选项才正常展示
        self.wait_elevisble(UserContactsListLocator.redis_region_options, doc)
        time.sleep(3)
        self.get_elements(UserContactsListLocator.redis_region_options, doc)[1].click()

    def redis_check_billing_method(self):
        doc = "校验Billing Method默认选项"
        billing_method_options = ["Subscription", "Pay-As-You-Go"]
        selected_class = "antd4-radio-button-checked"
        self.enter_redis_purchase()
        time.sleep(3)
        eles = self.get_elements(UserContactsListLocator.redis_billing_method_options, doc)

        assert eles[0].text == billing_method_options[0]
        assert eles[1].text == billing_method_options[1]
        assert selected_class in eles[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

    def redis_check_region(self):
        doc = "校验Region选项"
        region_options = ["id-jakarta-testbed-d01", "ap-southeast-5"]
        self.enter_redis_purchase()
        time.sleep(3)
        eles = self.get_elements(UserContactsListLocator.redis_region_options, doc)

        assert eles[0].text == region_options[0]
        assert eles[1].text == region_options[1]

    def redis_check_organization(self, cmdopt, email, get_database_source):
        doc = "校验Organization选项"

        self.enter_redis_purchase()
        time.sleep(3)
        org = BusinessCommonTools().get_org_name(cmdopt, email, get_database_source)

        assert self.get_element(UserContactsListLocator.organization_options, doc).text == org

    def redis_check_zone(self):
        doc = "校验Zone选项"
        self.enter_redis_purchase()
        time.sleep(3)
        assert self.get_element(UserContactsListLocator.zone_option, doc).text == "Jakarta Zone A"

    def redis_check_edition(self):
        doc = "校验Edition选项"
        edition_options = self.options["edition"]
        selected_class = "antd4-radio-button-checked"
        self.enter_redis_purchase()
        time.sleep(3)

        eles = self.get_elements(UserContactsListLocator.edition_options, doc)
        for ele in eles:
            assert edition_options[eles.index(ele)] == ele.text
        assert selected_class in eles[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

    def redis_check_version(self):
        doc = "校验Version选项"
        version_options = self.options["version"]
        selected_class = "antd4-radio-button-checked"
        self.enter_redis_purchase()
        time.sleep(3)

        eles = self.get_elements(UserContactsListLocator.version_options, doc)
        for ele in eles:
            assert version_options[eles.index(ele)] == ele.text
        assert selected_class in eles[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

    def redis_check_architecture_type(self):
        doc = "校验Architecture Type选项"
        architecture_type_options = self.options["architecture type"]
        selected_class = "antd4-radio-button-checked"
        self.enter_redis_purchase()
        time.sleep(3)

        eles = self.get_elements(UserContactsListLocator.architecture_type_options, doc)
        for ele in eles:
            assert architecture_type_options[eles.index(ele)] == ele.text
        assert selected_class in eles[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

    def get_shard_number(self, edition, version, architecture_type):
        doc = "校验Shard Number选项"
        self.get_elements(UserContactsListLocator.edition_options, doc)[self.options["edition"].index(edition)].click()
        self.get_elements(UserContactsListLocator.version_options, doc)[self.options["version"].index(version)].click()
        self.get_elements(UserContactsListLocator.architecture_type_options, doc)[self.options["architecture type"].index(architecture_type)].click()
        time.sleep(1)
        return self.get_element(UserContactsListLocator.shard_number_option, doc).text

    def redis_check_shard_number(self):

        self.enter_redis_purchase()
        time.sleep(3)

        assert self.get_shard_number("Community", "Redis 5.0", "Cluster") == "2 Shards"
        assert self.get_shard_number("Community", "Redis 5.0", "Standard") == "Standalone"
        assert self.get_shard_number("Community", "Redis 5.0", "Read/Write Splitting") == "Standalone"
        assert self.get_shard_number("Community", "Redis 4.0", "Cluster") == "2 Shards"
        assert self.get_shard_number("Community", "Redis 4.0", "Standard") == "Standalone"
        assert self.get_shard_number("Community", "Redis 4.0", "Read/Write Splitting") == "Standalone"
        assert self.get_shard_number("Enterprise", "Redis 5.0", "Cluster") == "2 Shards"
        assert self.get_shard_number("Enterprise", "Redis 5.0", "Standard") == "Standalone"
        assert self.get_shard_number("Enterprise", "Redis 5.0", "Read/Write Splitting") == "Standalone"

    def get_node_type(self, edition, version, architecture_type):
        doc = "校验Node Type选项"
        self.get_elements(UserContactsListLocator.edition_options, doc)[self.options["edition"].index(edition)].click()
        self.get_elements(UserContactsListLocator.version_options, doc)[self.options["version"].index(version)].click()
        self.get_elements(UserContactsListLocator.architecture_type_options, doc)[self.options["architecture type"].index(architecture_type)].click()
        time.sleep(1)
        return self.get_elements(UserContactsListLocator.node_type_options, doc)

    def redis_check_node_type(self):

        self.enter_redis_purchase()
        time.sleep(3)
        selected_class = "antd4-radio-button-checked"

        assert self.get_node_type("Community", "Redis 5.0", "Cluster")[0].text == "Master-Replica"
        assert self.get_node_type("Community", "Redis 5.0", "Standard")[0].text == "Master-Replica"

        options = self.get_node_type("Community", "Redis 5.0", "Read/Write Splitting")
        for option in options:
            assert option.text == self.options["node type"][options.index(option)]
            if options.index(option) == 0:
                assert selected_class in options[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

        assert self.get_node_type("Community", "Redis 4.0", "Cluster")[0].text == "Master-Replica"
        assert self.get_node_type("Community", "Redis 4.0", "Standard")[0].text == "Master-Replica"

        options = self.get_node_type("Community", "Redis 4.0", "Read/Write Splitting")
        for option in options:
            assert option.text == self.options["node type"][options.index(option)]
            if options.index(option) == 0:
                assert selected_class in options[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

        assert self.get_node_type("Enterprise", "Redis 5.0", "Cluster")[0].text == "Master-Replica"
        assert self.get_node_type("Enterprise", "Redis 5.0", "Standard")[0].text == "Master-Replica"

        options = self.get_node_type("Enterprise", "Redis 5.0", "Read/Write Splitting")
        for option in options:
            assert option.text == self.options["node type"][options.index(option)]
            if options.index(option) == 0:
                assert selected_class in options[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

    def enter_string(self, locator, content, doc, if_refresh=False):
        """ input string by locator """
        if if_refresh:
            self.driver.refresh()
        time.sleep(3)

        self.scroll_bar_operation(locator)
        self.send_keys(locator, content, doc)
        time.sleep(2)

    def generate_random_string(self, length_of_str: int):
        """ generate random string with ascii code and param length_of_str  """
        chars = string.ascii_letters + string.digits
        return ''.join(random.choice(chars) for _ in range(length_of_str))

    def redis_check_instance_name(self):
        doc = "检验Instance Name输入框"

        self.enter_redis_purchase()

        time.sleep(3)

        # 输入合规字符串
        self.enter_string(UserContactsListLocator.instance_name_input, "regular_name", doc)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-success"

        # 输入不以字母开头的字符串
        self.enter_string(UserContactsListLocator.instance_name_input, "123", doc, True)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入以http://开头的字符串
        self.enter_string(UserContactsListLocator.instance_name_input, "http://123", doc, True)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入以https://开头的字符串
        self.enter_string(UserContactsListLocator.instance_name_input, "https://123", doc, True)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入长度小于2的字符串
        self.enter_string(UserContactsListLocator.instance_name_input, "a", doc, True)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入长度大于80的字符串
        long_str = "a" + self.generate_random_string(80)
        self.enter_string(UserContactsListLocator.instance_name_input, long_str, doc, True)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入包含@/：==”<>{[]}或空格的字符串
        str_list = ["a@", "a==", "a\"", "a[]", "a a"]
        for name_str in str_list:
            self.enter_string(UserContactsListLocator.instance_name_input, name_str, doc, True)
            assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 不输入
        self.enter_string(UserContactsListLocator.instance_name_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.instance_name_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

    def assert_instance_type_options(self, assert_list, doc):
        self.click_element(UserContactsListLocator.instance_type_selector, doc)
        time.sleep(1)
        instance_type_options = self.get_elements(UserContactsListLocator.instance_type_options, doc)
        for option in instance_type_options:
            print(option.text)
            assert assert_list[instance_type_options.index(option)] == option.text

    def redis_check_instance_type(self):
        doc = "校验Instance Type选项"

        assert_data = {
            "Community": {
                "Redis 5.0": {
                    "Cluster": {
                        "Master-Replica": {
                            "2 Shards": ["2 GB Cluster (2 Shards)", "4 GB Cluster (2 Shards)", "8 GB Cluster (2 Shards)", "16 GB Cluster (2 Shards)", "32 GB Cluster (2 Shards)"],
                            "4 Shards": ["4 GB Cluster (4 Shards)", "8 GB Cluster (4 Shards)", "16 GB Cluster (4 Shards)", "24 GB Cluster (4 Shards)", "32 GB Cluster (4 Shards)",
                                         "64 GB Cluster (4 Shards)", "128 GB Cluster (4 Shards)", ],
                            "8 Shards": ["8 GB Cluster (8 Shards)", "16 GB Cluster (8 Shards)", "32 GB Cluster (8 Shards)", "48 GB Cluster (8 Shards)", "64 GB Cluster (8 Shards)",
                                         "128 GB Cluster (8 Shards)"],
                            "16 Shards": ["16 GB Cluster (16 Shards)", "32 GB Cluster (16 Shards)", "64 GB Cluster (16 Shards)", "96 GB Cluster (16 Shards)", "128 GB Cluster (16 Shards)",
                                          "256 GB Cluster (16 Shards)"],
                            "32 Shards": ["64 GB Cluster (32 Shards)", "128 GB Cluster (32 Shards)", "192 GB Cluster (32 Shards)", "256 GB Cluster (32 Shards)", "512 GB Cluster (32 Shards)", ],
                            "64 Shards": ["128 GB Cluster (64 Shards)", "256 GB Cluster (64 Shards)", "512 GB Cluster (64 Shards)", ],
                            "128 Shards": ["512 GB Cluster (128 Shards)", ],
                            "256 Shards": ["1024 GB Cluster (256 Shards)", "2048 GB Cluster (256 Shards)", "4096 GB Cluster (256 Shards)", ],
                        }
                    },
                    "Standard": {
                        "Master-Replica": {
                            "Standalone": ["256 MB Master-replica", "1 GB Master-replica", "2 GB Master-replica", "4 GB Master-replica", "8 GB Master-replica", "16 GB Master-replica",
                                           "32 GB Master-replica", "64 GB Master-replica"]
                        }
                    },
                    "Read/Write Splitting": {
                        "1 Read Replica": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "2 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "4 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "8 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "16 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "32 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "64 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                        ]},
                        "3 Read Replicas": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "2 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "4 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "8 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "16 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "32 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "64 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                        ]},
                        "5 Read Replicas": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "2 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "4 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "8 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "16 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "32 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "64 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                        ]}
                    }
                },
                "Redis 4.0": {
                    "Cluster": {
                        "Master-Replica": {
                            "2 Shards": ["2 GB Cluster (2 Shards)", "4 GB Cluster (2 Shards)", "8 GB Cluster (2 Shards)", "16 GB Cluster (2 Shards)", "32 GB Cluster (2 Shards)"],
                            "4 Shards": ["4 GB Cluster (4 Shards)", "8 GB Cluster (4 Shards)", "16 GB Cluster (4 Shards)", "24 GB Cluster (4 Shards)", "32 GB Cluster (4 Shards)",
                                         "64 GB Cluster (4 Shards)", "128 GB Cluster (4 Shards)", ],
                            "8 Shards": ["8 GB Cluster (8 Shards)", "16 GB Cluster (8 Shards)", "32 GB Cluster (8 Shards)", "48 GB Cluster (8 Shards)", "64 GB Cluster (8 Shards)",
                                         "128 GB Cluster (8 Shards)"],
                            "16 Shards": ["16 GB Cluster (16 Shards)", "32 GB Cluster (16 Shards)", "64 GB Cluster (16 Shards)", "96 GB Cluster (16 Shards)", "128 GB Cluster (16 Shards)",
                                          "256 GB Cluster (16 Shards)"],
                            "32 Shards": ["64 GB Cluster (32 Shards)", "128 GB Cluster (32 Shards)", "192 GB Cluster (32 Shards)", "256 GB Cluster (32 Shards)", "512 GB Cluster (32 Shards)", ],
                            "64 Shards": ["128 GB Cluster (64 Shards)", "256 GB Cluster (64 Shards)", "512 GB Cluster (64 Shards)", ],
                            "128 Shards": ["512 GB Cluster (128 Shards)", ],
                            "256 Shards": ["1024 GB Cluster (256 Shards)", "2048 GB Cluster (256 Shards)", "4096 GB Cluster (256 Shards)", ],
                        },

                    },
                    "Standard": {
                        "Master-Replica": {
                            "Standalone": ["256 MB Master-replica", "1 GB Master-replica", "2 GB Master-replica", "4 GB Master-replica", "8 GB Master-replica", "16 GB Master-replica",
                                           "32 GB Master-replica", "64 GB Master-replica"]
                        }
                    },
                    "Read/Write Splitting": {
                        "1 Read Replica": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "2 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "4 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "8 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "16 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "32 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                            "64 GB Read/Write Splitting (1 Shard, 1 Read Replica)",
                        ]},
                        "3 Read Replicas": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "2 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "4 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "8 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "16 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "32 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                            "64 GB Read/Write Splitting (1 Shard, 3 Read Replicas)",
                        ]},
                        "5 Read Replicas": {"Standalone": [
                            "1 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "2 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "4 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "8 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "16 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "32 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                            "64 GB Read/Write Splitting (1 Shard, 5 Read Replicas)",
                        ]}
                    }
                }
            },
            "Enterprise": {
                "Redis 5.0": {
                    "Cluster": {
                        "Master-Replica": {
                            "2 Shards": [
                                "2 GB Cluster Performance-enhanced (2 Shards)",
                                "4 GB Cluster Performance-enhanced (2 Shards)",
                            ],
                            "4 Shards": ["8 GB Cluster Performance-enhanced (4 Shards)"],
                            "8 Shards": [
                                "16 GB Cluster Performance-enhanced (8 Shards)",
                                "32 GB Cluster Performance-enhanced (8 Shards)",
                                "64 GB Cluster Performance-enhanced (8 Shards)",
                            ],
                            "16 Shards": [
                                "128 GB Cluster Performance-enhanced (16 Shards)",
                                "256 GB Cluster Performance-enhanced (16 Shards)",
                            ],
                            "32 Shards": ["512 GB Cluster Performance-enhanced (32 Shards)", ],
                            "64 Shards": ["1024 GB Cluster Performance-enhanced (64 Shards)", ],
                            "128 Shards": ["2048 GB Cluster Performance-enhanced (128 Shards)"],
                            "256 Shards": ["4096 GB Cluster Performance-enhanced (256 Shards)"]
                        }
                    },
                    "Standard": {
                        "Master-Replica": {
                            "Standalone": [
                                "1 GB Master-replica Performance-enhanced",
                                "2 GB Master-replica Performance-enhanced",
                                "4 GB Master-replica Performance-enhanced",
                                "8 GB Master-replica Performance-enhanced",
                                "16 GB Master-replica Performance-enhanced",
                                "32 GB Master-replica Performance-enhanced",
                                "64 GB Master-replica Performance-enhanced",
                            ]
                        }
                    },
                    "Read/Write Splitting": {
                        "1 Read Replica": {
                            "Standalone": [
                                "1 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replicas)",
                                "2 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replicas)",
                                "4 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replicas)",
                                "8 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replica)",
                                "16 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replica)",
                                "32 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replica)",
                                "64 GB Read/Write Splitting Performance-enhanced (1 Shard, 1 Read Replica)"
                            ]
                        },
                        "3 Read Replicas": {
                            "Standalone": [
                                "1 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "2 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "4 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "8 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "16 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "32 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)",
                                "64 GB Read/Write Splitting Performance-enhanced (1 Shard, 3 Read Replicas)"
                            ]
                        },
                        "5 Read Replicas": {
                            "Standalone": [
                                "1 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "2 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "4 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "8 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "16 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "32 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)",
                                "64 GB Read/Write Splitting Performance-enhanced (1 Shard, 5 Read Replicas)"
                            ]
                        }
                    }
                }
            }
        }

        self.enter_redis_purchase()
        time.sleep(3)

        self.scroll_bar_operation(UserContactsListLocator.organization_options)
        edition_options = self.get_elements(UserContactsListLocator.edition_options, doc)

        for edition in edition_options:
            edition.click()
            edition_text = edition.text
            version_options = self.get_elements(UserContactsListLocator.version_options, doc)
            for version in version_options:
                version.click()
                version_text = version.text
                architecture_type_options = self.get_elements(UserContactsListLocator.architecture_type_options, doc)
                for architecture_type in architecture_type_options:
                    architecture_type.click()
                    architecture_type_text = architecture_type.text
                    node_type_options = self.get_elements(UserContactsListLocator.node_type_options, doc)
                    for node_type in node_type_options:
                        node_type.click()
                        node_type_text = node_type.text
                        time.sleep(1)
                        self.click_element(UserContactsListLocator.shard_number_selector, doc)

                        shard_number_options = self.get_elements(UserContactsListLocator.shard_number_options, doc)
                        time.sleep(1)
                        self.click_element(UserContactsListLocator.shard_number_selector, doc)
                        for shard_number in shard_number_options:
                            shard_number_text = shard_number.text
                            self.click_element(UserContactsListLocator.shard_number_selector, doc)
                            time.sleep(1)
                            shard_number.click()
                            print(edition.text, ' ', version.text, ' ', architecture_type.text, ' ', node_type.text, ' ', shard_number.text)

                            self.assert_instance_type_options(
                                assert_data[edition_text][version_text][architecture_type_text][node_type_text][shard_number_text], doc
                            )

    def redis_check_ip_address_whitelist(self):
        doc = "校验IP Address Whitelist输入框"

        self.enter_redis_purchase()
        time.sleep(3)

        # 输入合规的ip地址
        self.enter_string(UserContactsListLocator.ip_address_whitelist_input, "192.168.1.0", doc)
        assert self.get_element(UserContactsListLocator.ip_address_whitelist_alert, doc).get_attribute("class") == "antd4-form-item-explain-success"
        self.enter_string(UserContactsListLocator.ip_address_whitelist_input, "192.168.1.0/16", doc, True)
        assert self.get_element(UserContactsListLocator.ip_address_whitelist_alert, doc).get_attribute("class") == "antd4-form-item-explain-success"

        # 输入不合规的ip地址
        self.enter_string(UserContactsListLocator.ip_address_whitelist_input, "abc", doc, True)
        assert self.get_element(UserContactsListLocator.ip_address_whitelist_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"
        self.enter_string(UserContactsListLocator.ip_address_whitelist_input, "192.168.1.0.16", doc, True)
        assert self.get_element(UserContactsListLocator.ip_address_whitelist_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 必填校验
        self.enter_string(UserContactsListLocator.ip_address_whitelist_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.ip_address_whitelist_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

    def redis_check_connection_password(self):
        doc = "校验Connection Password输入框"

        self.enter_redis_purchase()
        time.sleep(3)

        # 输入合规字符串
        self.enter_string(UserContactsListLocator.connection_password_input, "Test123456", doc)
        assert "antd4-form-item-has-success" in self.get_element((By.XPATH, "//label[@title='Connection Password']/../.."), doc).get_attribute("class")

        # 输入长度小于8位的字符串
        self.enter_string(UserContactsListLocator.connection_password_input, "Test1", doc, True)
        assert self.get_element(UserContactsListLocator.connection_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入长度大于32位的字符串
        self.enter_string(UserContactsListLocator.connection_password_input, "Test1" + self.generate_random_string(28), doc, True)
        assert self.get_element(UserContactsListLocator.connection_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入字符类型不满足3种的字符串
        self.enter_string(UserContactsListLocator.connection_password_input, "testtesttest", doc, True)
        assert self.get_element(UserContactsListLocator.connection_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入字符类型满足三种，但是特殊字符超过范围的字符串
        self.enter_string(UserContactsListLocator.connection_password_input, "Test12345.6", doc, True)
        assert self.get_element(UserContactsListLocator.connection_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 必填校验
        self.enter_string(UserContactsListLocator.connection_password_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.connection_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

    def redis_check_high_authority_account(self):
        doc = "校验High Authority Account输入框"

        self.enter_redis_purchase()
        time.sleep(3)

        # 输入合规字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "test1", doc)
        assert "antd4-form-item-explain-success" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 输入长度小于2位的字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "t", doc, True)
        assert "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 输入长度大于16位的字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "test" + self.generate_random_string(16), doc, True)
        assert "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 输入以数字开头的字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "12test", doc, True)
        assert "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 输入包含特殊字符的字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "te&st", doc, True)
        assert "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 输入关键字字符串
        self.enter_string(UserContactsListLocator.high_authority_account_input, "root", doc, True)
        assert "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

        # 必填校验
        self.enter_string(UserContactsListLocator.high_authority_account_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert  "antd4-form-item-explain-error" in self.get_element(UserContactsListLocator.high_authority_account_alert, doc).get_attribute("class")

    def redis_check_password(self):
        doc = "校验Password输入框"

        self.enter_redis_purchase()
        time.sleep(3)

        # 输入合规字符串
        self.enter_string(UserContactsListLocator.password_input, "Test123456", doc)
        assert "antd4-form-item-has-success" in self.get_element((By.XPATH, "//label[@title='Password']/../.."), doc).get_attribute("class")

        # 输入长度小于8位的字符串
        self.enter_string(UserContactsListLocator.password_input, "Test1", doc, True)
        assert self.get_element(UserContactsListLocator.password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入长度大于32位的字符串
        self.enter_string(UserContactsListLocator.password_input, "Test1" + self.generate_random_string(32), doc, True)
        assert self.get_element(UserContactsListLocator.password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入字符类型不满足3种的字符串
        self.enter_string(UserContactsListLocator.password_input, "testtesttest", doc, True)
        assert self.get_element(UserContactsListLocator.password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入字符类型满足三种，但是特殊字符超出范围的字符串
        self.enter_string(UserContactsListLocator.password_input, "Test12345.6", doc, True)
        assert self.get_element(UserContactsListLocator.password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 必填校验
        self.enter_string(UserContactsListLocator.password_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"


    def redis_check_confirm_password(self):
        doc = "校验Confirm Password输入框"

        self.enter_redis_purchase()
        time.sleep(3)

        # 没有输入password的时候，先输入confirm password
        self.enter_string(UserContactsListLocator.confirm_password_input, "Test123456", doc)
        assert self.get_element(UserContactsListLocator.confirm_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入与password不同
        self.enter_string(UserContactsListLocator.password_input, "Test123456", doc, True)
        time.sleep(1)
        self.enter_string(UserContactsListLocator.confirm_password_input, "Test12345678", doc)
        assert self.get_element(UserContactsListLocator.confirm_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"

        # 输入与password相同
        self.enter_string(UserContactsListLocator.password_input, "Test123456", doc, True)
        time.sleep(1)
        self.enter_string(UserContactsListLocator.confirm_password_input, "Test123456", doc)
        assert self.get_element(UserContactsListLocator.confirm_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-success"

        # 必填校验
        self.enter_string(UserContactsListLocator.confirm_password_input, "", doc, True)
        self.click_element(UserContactsListLocator.buy_now_button, doc)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.confirm_password_alert, doc).get_attribute("class") == "antd4-form-item-explain-error"


    def redis_check_validity_period(self):
        doc = "校验Validity Period选择框"

        self.enter_redis_purchase()
        time.sleep(3)

        selected_class = "antd4-radio-button-checked"

        self.scroll_bar_operation(UserContactsListLocator.validity_period_options)
        validity_period_options = self.get_elements(UserContactsListLocator.validity_period_options, doc)
        for option in validity_period_options:
            assert self.options["validity period"][validity_period_options.index(option)] == option.text

        assert selected_class in validity_period_options[0].find_element(By.XPATH, ".//label[1]/span[1]").get_attribute("class")

        self.driver.refresh()
        time.sleep(3)
        self.get_elements(UserContactsListLocator.redis_billing_method_options, doc)[1].click()
        time.sleep(1)
        self.scroll_bar_operation(UserContactsListLocator.order_setting_title)
        time.sleep(1)
        assert self.get_element(UserContactsListLocator.order_setting_title, doc).find_elements(By.XPATH, "./../..//label[@title]")[0].text == "Expired Time"



    def redis_check_price_style(self):
        doc = "校验不同付费方式的询价样式"
        self.enter_redis_purchase()
        time.sleep(3)

        self.get_elements(UserContactsListLocator.redis_billing_method_options, doc)[0].click()
        assert len(self.get_elements(UserContactsListLocator.price_style_items, doc)) == 1

        self.driver.refresh()
        time.sleep(3)

        self.get_elements(UserContactsListLocator.redis_billing_method_options, doc)[1].click()
        time.sleep(2)
        assert len(self.get_elements(UserContactsListLocator.price_style_items, doc)) == 2
        assert self.get_elements(UserContactsListLocator.price_style_items, doc)[1].text == "/Hour"

    def redis_enter_redis_console(self):
        doc = "校验Redis控制台入口以及列表字段"

        self.enter_product_by_name("Redis")
        time.sleep(3)

        redis_console_table_columns = self.get_elements(UserContactsListLocator.redis_console_table_columns, doc)

        for col in redis_console_table_columns:
            assert self.table_columns["Redis console"][redis_console_table_columns.index(col)] == col.text

    # ========================================Product EIP Pages==============================================

    eip_purchase_items ={
        "subscription": ["Billing Method", "Region", "Organization", "Line Type", "Network Type", "Maximum Bandwidth", "Validity Period", "Quantity", "Enable Auto-renewal"],
        "pay-as-you-go": ["Billing Method", "Region", "Organization", "Line Type", "Network Type", "Maximum Bandwidth", "Charging Method", "Quantity", "Expired Time"]
    }

    eip_console = {
        "columns": ["EIP ID/Name", "IP status", "Tag", "IP address", "Bandwidth", "Organization/Resource Set", "Bind instance type/ID", "Line Type/Network Type", "Created At", "Operation"],
        "detail": ["Organization", "Region", "Line Type", "Instance Name", "Network Type", "Maximum Bandwidth", "Validity Period", "Charging Method", "Quantity", "Enable Auto-renewal"]
    }



    def enter_eip_purchase(self):
        doc = "进入EIP购买页面"
        self.click_element(UserContactsListLocator.my_resource_tab, doc)
        time.sleep(3)
        self.move_mouse_to_element(UserContactsListLocator.my_resource_create_new_button)
        time.sleep(1)
        self.click_element(UserContactsListLocator.my_resource_create_eip_button, doc)

        self.switch_to_new_window()

    def eip_check_eip_purchase(self):
        doc = "验证公有云购买页面默认展现"

        self.enter_eip_purchase()
        time.sleep(5)

        eip_purchase_items = self.get_elements(UserContactsListLocator.eip_purchase_item, doc)

        for item in eip_purchase_items:
            assert self.eip_purchase_items["subscription"][eip_purchase_items.index(item)] == item.text

        time.sleep(3)
        self.driver.refresh()
        time.sleep(5)
        self.click_element(UserContactsListLocator.billing_method_payg_button, doc)
        self.click_element(UserContactsListLocator.billing_method_payg_button, doc)
        time.sleep(3)
        eip_purchase_items = self.get_elements(UserContactsListLocator.eip_purchase_item, doc)
        for item in eip_purchase_items:
            print(item.text)
            assert self.eip_purchase_items["pay-as-you-go"][eip_purchase_items.index(item)] == item.text


    def eip_release_single_instance(self):
        doc = "释放单个公有云EIP实例"
        self.enter_product_by_name("Elastic IP Addresses")
        time.sleep(5)

        self.driver.switch_to.frame(self.get_element(UserContactsListLocator.iframe_resource_orchestration_service, doc))
        self.wait_elevisble(UserContactsListLocator.eip_console_release_button, doc)

        time.sleep(3)
        self.click_by_js(UserContactsListLocator.eip_console_release_button, doc)
        time.sleep(2)
        self.get_elements(UserContactsListLocator.layer_button, doc)[1].click()

    def eip_click_binding_resource(self):
        doc = "点击Binding Resource按钮"
        self.enter_product_by_name("Elastic IP Addresses")
        time.sleep(5)
        self.driver.switch_to.frame(self.get_element(UserContactsListLocator.iframe_resource_orchestration_service, doc))

        self.wait_elevisble(UserContactsListLocator.eip_binding_resource_button, doc)
        time.sleep(3)
        self.click_element(UserContactsListLocator.eip_binding_resource_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserContactsListLocator.layer_title, doc)

    def eip_click_binding_resource_instance(self):
        doc = "点击Binding Resource按钮"
        self.eip_click_binding_resource()
        time.sleep(3)
        self.click_element(UserContactsListLocator.layer_instance_type_selector, doc)
        time.sleep(3)
        options = self.get_elements(UserContactsListLocator.layer_instance_type_selector_option, doc)
        assert options[0] == "ECS instance"
        assert options[1] == "SLB instance"
        assert options[3] == "Auxiliary ENI"


    def enter_eip_console(self):
        doc = "进入EIP控制台页面"
        self.enter_product_by_name("Elastic IP Addresses")
        time.sleep(5)
        self.driver.switch_to.frame(self.get_element(UserContactsListLocator.iframe_resource_orchestration_service, doc))

        self.wait_elevisble(UserContactsListLocator.eip_console_create_button, doc)
        time.sleep(3)

        assert self.get_element(UserContactsListLocator.console_page_title, doc).text == "Virtual Private Cloud"

        item_active_class = "main-item-active"
        assert item_active_class in self.get_element(UserContactsListLocator.eip_item, doc).get_attribute('class')


    def enter_eip_create(self):
        doc = "进入EIP创建页面"
        self.enter_eip_console()

        self.click_element(UserContactsListLocator.eip_console_create_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserContactsListLocator.eip_create_page_title, doc)
        assert self.get_element(UserContactsListLocator.eip_create_page_title, doc).text == "Create EIP"




    def eip_check_console_table(self):
        doc = "校验EIP实例列表字段"
        self.enter_eip_console()
        columns = self.get_elements(UserContactsListLocator.eip_console_table_columns, doc)

        for column in columns:
            assert self.eip_console["columns"][columns.index(column)] == column.text



    def eip_check_purchase_cashier_page(self):
        doc = "校验EIP购买支付页面展示"
        self.enter_eip_purchase()
        time.sleep(3)
        self.wait_elevisble(UserContactsListLocator.buy_now_button, doc)
        time.sleep(5)
        self.click_by_js(UserContactsListLocator.buy_now_button, doc)
        self.wait_elevisble(UserContactsListLocator.eip_pay_card_title, doc)

        card_titles = self.get_elements(UserContactsListLocator.eip_pay_card_title, doc)
        assert card_titles[0].text == "Order Detail"
        assert card_titles[1].text == "Payment Summary"
        time.sleep(3)
        self.move_mouse_to_element(UserContactsListLocator.eip_pay_detail)
        time.sleep(1)
        detail_items = self.get_elements(UserContactsListLocator.eip_pay_detail_item, doc)
        for item in detail_items:
            print(item.text[0:-1])
            assert item.text[0:-1] in self.eip_console["detail"]






